package com.pingba.convert;

import com.pingba.entity.msg.MsgSend;
import com.pingba.view.nearby.MsgSendView;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 视图转化，供客户端在地图页面展示用
 * Created by Administrator on 2015/12/10 0010.
 */
public class MsgSendConvert {

    public static List<MsgSendView> convert2List(List<MsgSend> nearByList, List<MsgSend> subscribeList) {
        List<MsgSendView> viewList = new ArrayList<MsgSendView>();

        Set<Long> subscribeIdList = new HashSet<Long>();
        for (MsgSend subscribe : subscribeList) {
            subscribeIdList.add(subscribe.getSid());
        }
        for (MsgSend nearBy : nearByList) {
            MsgSendView msgSendView = defaultConvert(nearBy);
            if (subscribeIdList.contains(nearBy.getSid())) {
                msgSendView.setIsLike(true);
            }
            viewList.add(msgSendView);
        }
        return viewList;
    }

    public static MsgSendView defaultConvert(MsgSend msgSend) {
        MsgSendView msgSendView = new MsgSendView();
        msgSendView.setContent(msgSend.getContent());

        msgSendView.setExpireTime(msgSend.getExpireTime());

        msgSendView.setHaveResponse(msgSend.isHaveResponse());

        msgSendView.setHeadUrl(msgSend.getHeadUrl());

        msgSendView.setImgUrl1(msgSend.getImgUrl1());


        msgSendView.setImgUrl2(msgSend.getImgUrl2());

        msgSendView.setIsLike(false);

        msgSendView.setLatitude(msgSend.getLatitude());

        msgSendView.setLocation(msgSend.getLocation());

        msgSendView.setLongitude(msgSend.getLongitude());

        msgSendView.setPublishTime(msgSend.getPublishTime());

        msgSendView.setReaded(msgSend.isReaded());

        msgSendView.setSid(msgSend.getSid());

        msgSendView.setTitle(msgSend.getTitle());

        msgSendView.setTypeId(msgSend.getTypeId());

        msgSendView.setUserId(msgSend.getUserId());

        msgSendView.setUserName(msgSend.getUserName());
        return msgSendView;
    }
}
